package com.ruoyi.result.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.result.domain.ResultThesis;
import com.ruoyi.result.service.IResultThesisService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论文Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("论文管理")
@RestController
@RequestMapping("/result/thesis")
public class ResultThesisController extends BaseController
{
    @Autowired
    private IResultThesisService resultThesisService;

    /**
     * 查询论文列表
     */
    @ApiOperation("查询论文列表")   
    @GetMapping("/my")
    public TableDataInfo my(ResultThesis resultThesis)
    {
    	resultThesis.setUserIds(","+SecurityUtils.getLoginUser().getUser().getUserId()+",");
        startPage();
        List<ResultThesis> list = resultThesisService.selectResultThesisList(resultThesis);
        return getDataTable(list);
    }
    
    /**
     * 查询论文列表
     */
    @ApiOperation("查询论文列表")   
    @PreAuthorize("@ss.hasPermi('result:thesis:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResultThesis resultThesis)
    {
        startPage();
        List<ResultThesis> list = resultThesisService.selectResultThesisList(resultThesis);
        return getDataTable(list);
    }

    /**
     * 导出论文列表
     */
    @ApiOperation("导出论文列表")    
    @PreAuthorize("@ss.hasPermi('result:thesis:export')")
    @Log(title = "论文", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ResultThesis resultThesis)
    {
        List<ResultThesis> list = resultThesisService.selectResultThesisList(resultThesis);
        ExcelUtil<ResultThesis> util = new ExcelUtil<ResultThesis>(ResultThesis.class);
        return util.exportExcel(list, "thesis");
    }

    /**
     * 获取论文详细信息
     */
    @ApiOperation("获取论文详细信息")
    @ApiImplicitParam(name = "id", value = "论文ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('result:thesis:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(resultThesisService.selectResultThesisById(id));
    }

    /**
     * 新增论文
     */
    @ApiOperation("新增论文")
    @PreAuthorize("@ss.hasPermi('result:thesis:add')")
    @Log(title = "论文", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResultThesis resultThesis)
    {
        return toAjax(resultThesisService.insertResultThesis(resultThesis));
    }

    /**
     * 修改论文
     */
    @ApiOperation("修改论文")  
    @PreAuthorize("@ss.hasPermi('result:thesis:edit')")
    @Log(title = "论文", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResultThesis resultThesis)
    {
        return toAjax(resultThesisService.updateResultThesis(resultThesis));
    }

    /**
     * 删除论文
     */
    @ApiOperation("删除论文")
    @ApiImplicitParam(name = "id", value = "论文ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('result:thesis:remove')")
    @Log(title = "论文", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resultThesisService.deleteResultThesisByIds(ids));
    }
}
